package com.sky;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.core.*;

import javax.swing.text.html.parser.Entity;
import java.io.IOException;
import java.util.List;

@SpringBootTest
public class RedisTemplateTest01 {
@Autowired
    private RedisTemplate redisTemplate;
@Test
    public void RedisTest(){
   // ValueOperations valueOperations = redisTemplate.opsForValue();
   // valueOperations.set("username","zhangsan");
    HashOperations hashOperations = redisTemplate.opsForHash();
    hashOperations.put("myhash","likes","20");
    ListOperations listOperations = redisTemplate.opsForList();
    listOperations.leftPush("list1","a");
    listOperations.leftPush("list1","b");
    listOperations.leftPush("list1","c");
    Object o = listOperations.rightPop("list1");
    System.out.println(o);
    GeoOperations geoOperations = redisTemplate.opsForGeo();
    geoOperations.add("location",new Point(114.20,44.20),"shop1");
    List position = geoOperations.position("location", "shop1");
    System.out.println(position);
    HyperLogLogOperations hyperLogLogOperations = redisTemplate.opsForHyperLogLog();
    hyperLogLogOperations.add("signs","a","b","a","d");
    Long signs = hyperLogLogOperations.size("signs");
    System.out.println(signs);
}
@Test
    public void httpClientTest() throws IOException {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet("http://localhost:8080/user/shop/status");
        CloseableHttpResponse response = client.execute(httpGet);
        int statusCode = response.getStatusLine().getStatusCode();
        System.out.println("响应状态码"+statusCode);
        HttpEntity entity = response.getEntity();
        System.out.println("响应数据"+ EntityUtils.toString(entity));
        response.close();
        client.close();
    }
}
